#!/usr/bin/env python
import ConfigParser

class Servers( object ):

    def __init__( self ):
        self.__configfile = "servers.cfg"

        self.configurator = ConfigParser.ConfigParser()
        self.configurator.read( self.__configfile )

    def getSections( self ):
        return self.configurator.sections()

    def getList( self ):
        for server in self.getSections():
            print "##### %s ######" % server
            for item in self.configurator.items( server ):
                print "%s :: %s" % (item[0], item[1])

    def getServerInfo( self, name ):
        if name in self.getSections():
            ip   = self.configurator.items( name )[0][1]
            user = self.configurator.items( name )[1][1]
                  
            return {'ip':ip, 'user':user, 'tunnel':None} 

    def doConnection( self, name ):
        server = self.getServerInfo( name )
        print "ssh %s -l %s" % (server['ip'], server['user'])

        
if __name__ == '__main__':
    config = Servers()
    config.getList()
    config.doConnection('worf')
